package common;

import java.io.Serializable;
import java.util.List;

public class Board implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 1532057627839157432L;
    Tile[][] board;
    boolean[] companies = new boolean[7];

    public Board(List<Tile> tileList) {
        board = new Tile[9][12];

        for (Tile tile : tileList) {
            board[tile.getLocation().getX()][tile.getLocation().getY()] = tile;
        }

        for (int i = 0; i < 7; i++) {
            companies[i] = false;
        }
    }

    public Tile getTile(Coordinate cord) {
        return board[cord.getX()][cord.getY()];
    }

    public Tile getTile(int x, int y) {
        return board[x][y];
    }

    public void setCompanyOnBoard(enumCompany company, boolean isOnBoard)
    {
    	companies[company.getIndex()]= isOnBoard;
    }
    
        
    public boolean isCompanyOnBoard(enumCompany company) {
        return companies[company.getIndex()];
    }

    public int numOfCompaniesOnBoard() {
        int count = 0;
        for (int i = 0; i < 7; i++) {
            if (companies[i])
                count++;
        }
        return count;
    }
    
    public Tile[] getNeighbors(Tile tile)
    {
    	int x;
    	int y;
    	x = tile.getLocation().getX();
        y = tile.getLocation().getY();
        Tile[] Neighbors = new Tile[4];
            	
    	if (x>0)
    	{
    		Neighbors[0] = board[x-1][y];
    	}
    	if (x<8)
    	{
    		Neighbors[1] = board[x+1][y];
    	}
    	if (y>0)
    	{
    		Neighbors[2] = board[x][y-1];
    	}
    	if (y<11)
    	{
    		Neighbors[3] = board[x][y+1];
    	}
    	
    	return Neighbors;
    }
}
